package com.toune.movie.mvp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.bumptech.glide.Glide;
import com.toune.movie.R;
import com.toune.movie.base.AppConstant;
import com.toune.movie.base.BaseActivity;
import com.toune.movie.base.myUtil.MyUtil;
import com.toune.movie.mvp.contract.SplashContract;
import com.toune.movie.mvp.presenter.SplashPresenter;
import com.vondear.rxtool.RxActivityTool;
import com.vondear.rxtool.RxDataTool;
import com.vondear.rxtool.RxSPTool;


import butterknife.BindView;
import cn.lemon.view.Action;
import cn.lemon.view.CountdownView;

/**
 * Created by Administrator on 2018/5/5.
 */

public class SplashActivity extends BaseActivity<SplashPresenter> implements SplashContract.View {
    @BindView(R.id.imageView2)
    ImageView imageView2;
    @BindView(R.id.countdown)
    CountdownView mCountdownView;
    private boolean isGo = false;

    @Override // 实例化presenter
    public SplashPresenter initPresenter() {
        return new SplashPresenter();
    }

    @Override
    public void loadMore() {

    }

    @Override
    public void refreData() {

    }

    @Override
    public void init(Bundle savedInstanceState) {
//        LocalFileService.startThis(context);
//        SystemService.startThis(context);
        if (RxSPTool.getInt(context, "playType") != 0) {
            AppConstant.PLAY_TYPE = RxSPTool.getInt(context, "playType");
        }
        if (!RxDataTool.isEmpty(RxSPTool.getString(context, AppConstant.SPLASH_IMG_URL))) {
            Glide.with(context).load(RxSPTool.getString(context, AppConstant.SPLASH_IMG_URL)).into(imageView2);
        }
        mCountdownView.setText("跳过");
        mCountdownView.setTime(5000);
        mCountdownView.star();
        mCountdownView.setOnFinishAction(new Action() {
            @Override
            public void onAction() {
                if (!isGo) {
                    RxActivityTool.skipActivityAndFinish(SplashActivity.this, MainActivity.class);
                    isGo = true;
                }
            }
        });
        mCountdownView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isGo) {
                    RxActivityTool.skipActivityAndFinish(SplashActivity.this, MainActivity.class);
                    isGo = true;
                }
            }
        });
        imageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!RxDataTool.isEmpty(RxSPTool.getString(context, AppConstant.SPLASH_URL))) {
                    MyUtil.intentToLocalChrom(context, RxSPTool.getString(context, AppConstant.SPLASH_URL));
                }
            }
        });
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_splash;
    }

    @Override
    protected String getTitleStr() {
        return null;
    }

    @Override
    protected void initEventAndData() {

    }

    @Override
    public void showError(String msg) {

    }

    @Override
    public void useNightMode(boolean isNight) {

    }
}
